//
//  LogonRequest.swift
//  PokeMaster
//
//  Created by 李腾芳 on 2022/1/11.
//  Copyright © 2022 OneV's Den. All rights reserved.
//

import Foundation
import Combine

struct LogonRequest {
    let email: String
    let password: String
    var publisher: AnyPublisher<User, AppError> {        
        Future { promise in
            DispatchQueue.global().asyncAfter(deadline: .now() + 1.5) {
                if !self.password.isEmpty, !self.email.isEmpty, self.password == "12345" {
                    let user = User(email: self.email, favoritePokemonIDs: [])
                    promise(.success(user))
                } else {
                    promise(.failure(.passwordError))
                }
            }
        }
        .receive(on: DispatchQueue.main)
        .eraseToAnyPublisher()
    }
}
